<?php
$keyword = $_GET['keyword'];
$page = !($_GET['page'])?'1':intval($_GET['page']);
$parentid = intval($_GET['parentid'])?intval($_GET['parentid']):"";
$all = intval($_GET['all'])?intval($_GET['all']):"";
$menustatus=array(1=>'显示',0=>'隐藏');
$pagesize = 20;
$page2 = ($page-1) * $pagesize;

if ($parentid == "") {
	$selpad = "";
} else {
	$selpad = " and parentid=" . $parentid;
} 
if ($all == 1) {
	$selpad = " and parentid=0";
} 

$sql = "select * from " . $BIAOTOU . $menu . " where ((name like '%" . $keyword . "%' or url like '%" . $keyword . "%')" . $selpad . ")";
$rs = mysql_query($sql);
$total = mysql_num_rows($rs);

$sql = "select * from " . $BIAOTOU . $menu . " where ((name like '%" . $keyword . "%' or url like '%" . $keyword . "%')" . $selpad . ") order by listorder  desc ,id desc limit $page2,$pagesize";
$rs = mysql_query($sql);

function role_chekcbox($id){
	global $BIAOTOU;
	$str='';
    $sql="select a.role_id,b.name from ".$BIAOTOU."access as a,".$BIAOTOU."role as b where a.menu_id=".$id." and a.role_id=b.id";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query)){
        $str.='<label>'.$row['name'].':<input type="checkbox" checked="checked" disabled="disabled" /></label>';
    }
	return $str;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link href="../css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.STYLE3 {color: #FF0000}
-->
</style>
<script language='javascript'>
function del($url)
{
if (confirm('确实要删除？')){
location.href=$url;
}
}
</script>
</head>

<body topmargin="5" leftmargin="0">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="282" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <table cellspacing="0" width="100%" height="207" style="border:1px  solid #DCEAF7;">
            <tr>
              <td width="220" height="30" bgcolor="E9F2FB" class="bigtext"><strong>&nbsp;<img src="../../images/arrow.gif" width="16" height="22" align="absmiddle" />菜单管理 [ <a href="admin.php?act=addmenu" class="link3">新增菜单</a> ] </strong></td>
              <td width="110" bgcolor="E9F2FB" class="bigtext"><a href="admin.php?act=menulist">全部</a></td>
              <td width="110" bgcolor="E9F2FB" class="bigtext"><a href="admin.php?act=menulist&all=1">显示根级别</a></td>
              <form id="form1" name="form1" method="get" action="">
              <input type="hidden" name="act" value="menulist"/>
              <td width="348" height="30" bgcolor="E9F2FB" class="bigtext">
                <label>操作名称或者url
                  <input type="text" class="btn3" name="keyword" />
                </label>
                            <label>
                            <input type="submit" name="Submit" value="查找" />
                            </label>
             
              </td> </form>
              <td width="188" align="right" bgcolor="E9F2FB" class="bigtext">共有 <b><?php echo $total;
?></b> 条记录&nbsp;&nbsp;</td>
            </tr>
            <tr>
              <td colspan="5" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><table width="100%" border=1 cellpadding=0 cellspacing=0
style="border-collapse: collapse" bordercolor="#dddddd">
                  
                    <tr>
                      <td width="5%"  height="30" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;ID</strong></td>
                      <td width="5%"  height="30" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>父ID</strong></td>
					  <td width="11%" bgcolor="#F2F2F2"  align="center" class="bigtext">&nbsp;<strong>名称</strong></td>
                      <td width="" bgcolor="#F2F2F2"  align="center" class="bigtext">&nbsp;<strong>操作url</strong></td>
                      <td width="40%" bgcolor="#F2F2F2"  align="center" class="bigtext">&nbsp;<strong>所属权限组</strong></td>
                      <td width="7%" bgcolor="#F2F2F2"  align="center" class="bigtext"><strong>是否显示</strong></td>
					  <td width="5%"  height="30" bgcolor="#F2F2F2"  align="center" class="bigtext"><strong>&nbsp;排序</strong></td>
					  <td width="8%"  align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;修改</strong></td>
                    </tr>
					<?php
while ($row = mysql_fetch_array($rs)) {
	$s=role_chekcbox($row["id"]);
	echo "<tr>";
	echo "<td height=30 class=bigtext align=\"center\">&nbsp;<a href=admin.php?act=menulist&parentid=" . $row["id"] . ">" . $row["id"] . "</a></td>";
	echo "<td height=30 class=bigtext align=\"center\">&nbsp;<a href=admin.php?act=menulist&parentid=" . $row["parentid"] . ">" . $row["parentid"] . "</a></td>";
	echo "<td height=30 class=bigtext align=\"center\">&nbsp;" . $row["name"] . "</td>";
	echo "<td height=30 class=bigtext>&nbsp;" . $row["url"] . "</td>";
	echo "<td height=30 class=bigtext align=\"center\">&nbsp;".$s."</td>";
	echo "<td height=30 class=bigtext align=\"center\">&nbsp;" . $menustatus[$row["status"]] . "</td>";
	echo "<td height=30 class=bigtext align=\"center\">&nbsp;" . $row["listorder"] . "</td>";
	echo "<td align=center class=bigtext><a href=admin.php?act=addmenu&id=" . $row["id"] . " class=link4>修改</a> <a href=# onclick=del('admin.php?act=delmenu&id=" . $row["id"] . "') class=link4>删除</a></td>";
	echo "</tr>";
} 

?>
                  </table>
				  <div class="yahoo2" style=" margin-top:30px;"><?php
pageft($total, $pagesize, 1, 1, 0, 10, "admin.php?act=menulist&keyword=" . urlencode($keyword) . "&parentid=" . $parentid);
echo $pagenav;
?></div></td>
                </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>
      
    </table></td>
  </tr>
</table>
</body>
</html>
<?php mysql_close();
?>
